package com.hu.hutool.Clone;

import cn.hutool.core.clone.CloneRuntimeException;
import cn.hutool.core.clone.Cloneable;
import lombok.Data;

/**
 * @Author CazCen
 * @Date 2021-10-12
 */

/**
 * 泛型克隆接口：通过实现接口的方式实现克隆
 * 通过实现 cn.hutool.core.clone.Cloneable 接口让一个类可克隆
 * 实列见测试类 UserCloneableTest
 * 实现Cloneable接口后克隆的对象是浅克隆
 */
@Data
public class UserCloneable implements Cloneable<UserCloneable> {

    private String name = "cazcen";
    private Integer age = 30;


    @Override
    public UserCloneable clone() {
        try {
            return (UserCloneable) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            throw new CloneRuntimeException(e);
        }
    }
}
